package com.yms.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yms.mapper.CompanyMapper;
import com.yms.pojo.Company;
import com.yms.pojo.PageResult;
import com.yms.service.ICompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2020-03-20
 */
@Service
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements ICompanyService {
    @Autowired
    private CompanyMapper companyMapper;


    @Override
    public PageResult<Company> selectMore(Integer page, Integer rows, Company companyCondition) {
        IPage<Company> companypage = new Page<>(page, rows);
        QueryWrapper<Company> queryWrapper = new QueryWrapper<>();
        if (companyCondition.getCname()!=null&&companyCondition.getCname()!=""){
            queryWrapper.like("cname",companyCondition.getCname());

        }
        if (companyCondition.getStatus()!=null&&companyCondition.getStatus()!=""){
            queryWrapper.eq("status",companyCondition.getStatus());

        }
        if("asc".equals(companyCondition.getOrderSort())){
            queryWrapper.orderByAsc("ordernumber");
        }else {
            queryWrapper.orderByDesc("ordernumber");
        }
        IPage<Company> companyIpage = companyMapper.selectPage(companypage, queryWrapper);
      //  IPage<Company> companyIpage = companyMapper.selectMore(companypage,companyCondition);
        PageResult<Company> pageResult = new PageResult<>();
        pageResult.setTotal(companyIpage.getTotal());
        pageResult.setRows(companyIpage.getRecords());
        return pageResult;
    }

    @Override
    public Integer reg(Company company) {
        company.setStarttime(LocalDateTime.now());
        company.setStatus("1");
        int insert = companyMapper.insert(company);
        return insert;
    }
}
